import { Permission } from '@/config'
import { DirectiveBinding } from 'vue'

function checkArray(key: string) {
  return Permission.includes(key)
}

const permission = {
  mounted: function (el: HTMLElement, binding: DirectiveBinding) {
    const permission = binding.value // 获取到 v-permission的值
    if (permission) {
      const hasPermission = checkArray(permission)
      if (!hasPermission) {
        // 没有权限 移除Dom元素
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
}
export default permission
